//
//  RegistViewController.m
//  WE
//
//  Created by 然然 on 15/11/17.
//  Copyright © 2015年 然然. All rights reserved.
//

#import "RegistViewController.h"
#import "LoginViewController.h"

@interface RegistViewController ()

@property (weak, nonatomic) IBOutlet UITextField *userNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UITextField *telephoneTextField;
@property (weak, nonatomic) IBOutlet UIButton *getAuthCodeButton;
@property (weak, nonatomic) IBOutlet UITextField *authCodeTextField;
@property (weak, nonatomic) IBOutlet UIButton *registButton;



@end

@implementation RegistViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    [self setUpSubViews];
    
    
}


-(void)setUpSubViews
{
    self.getAuthCodeButton.layer.cornerRadius = 5;
}



- (IBAction)getAuthCodeButtonAction:(id)sender {
    // 发送短信验证码
    [AVOSCloud requestSmsCodeWithPhoneNumber:self.telephoneTextField.text appName:nil operation:nil timeToLive:0 callback:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            NSLog(@"发送成功");
        }else {
            NSLog(@"失败---%@", error);
        }
    }];
}



- (IBAction)registButtonAction:(id)sender {
    [AVUser signUpOrLoginWithMobilePhoneNumberInBackground:self.telephoneTextField.text smsCode:self.authCodeTextField.text block:^(AVUser *user, NSError *error) {
        if (user) {
            [user setObject:self.passwordTextField.text forKey:@"password"];
            [user setObject:self.userNameTextField.text forKey:@"username"];
            [user save];
            NSLog(@"注册成功");
            LoginViewController *userVC = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:[NSBundle mainBundle]];
            [self presentViewController:userVC animated:YES completion:nil];
            
        }else {
            NSLog(@"注册失败 %@", error);
        }
    }];

}









- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
